

#ifndef THREAD_SEARCH_H
#define THREAD_SEARCH_H

#include <wx/string.h>
#include <wx/splitter.h>

#include <cbplugin.h> #include <globals.h>
#include "ThreadSearchFindData.h"
#include "ThreadSearchViewManagerBase.h"
#include "ThreadSearchLoggerBase.h"
#include "InsertIndexManager.h"
#include "codesnippetsevent.h"

class wxBoxSizer;
class wxWindow;
class wxMenu;
class wxMenuBar;
class wxToolBar;
class wxLogWindow;
class wxComboBox;
class FileTreeData;
class wxCommandEvent;
class wxUpdateUIEvent;
class cbAuiNotebook;

class cbConfigurationPanel;
class cbProject;

class ThreadSearchView;
class SnipSearchAppFrame;
class MainPanel;


class ThreadSearch : public cbPlugin

{
    friend class ThreadSearchFrame;

private:

	ThreadSearch();
public:

	ThreadSearch(wxWindow* parent);


	virtual ~ThreadSearch();


	virtual int GetConfigurationPriority() const { return 50; }


	virtual int GetConfigurationGroup() const { return cgContribPlugin; }


	virtual cbConfigurationPanel* GetConfigurationPanel(wxWindow* parent);


	virtual cbConfigurationPanel* GetProjectConfigurationPanel(wxWindow* WXUNUSED(parent), cbProject* WXUNUSED(project)){ return 0; }


	virtual void BuildMenu(wxMenuBar* menuBar);


	virtual void BuildModuleMenu(const ModuleType type, wxMenu* pMenu, const FileTreeData* data = 0);


	virtual bool BuildToolBar(wxToolBar* toolBar);


	void Notify();


	void SetCtxMenuIntegration(bool ctxMenuIntegration)    {m_CtxMenuIntegration = ctxMenuIntegration;}
	void SetUseDefValsForThreadSearch(bool useDefVals)     {m_UseDefValsForThreadSearch = useDefVals;}
	void SetShowSearchControls(bool showSearchControls)    {m_ShowSearchControls = showSearchControls;}
	void SetShowDirControls(bool showDirControls)          {m_ShowDirControls = showDirControls;}
	void SetShowCodePreview(bool showCodePreview)          {m_ShowCodePreview = showCodePreview;}
	void SetDisplayLogHeaders(bool displayLogHeaders)      {m_DisplayLogHeaders = displayLogHeaders;}
	void SetDrawLogLines(bool drawLogLines)                {m_DrawLogLines = drawLogLines;}
	void SetFindData(const ThreadSearchFindData& findData) {m_FindData = findData;}

	void SetManagerType (ThreadSearchViewManagerBase::eManagerTypes mgrType);
	void SetLoggerType (ThreadSearchLoggerBase::eLoggerTypes       lgrType) {m_LoggerType = lgrType;}
	void SetSplitterMode(wxSplitMode                                splitterMode) {m_SplitterMode = splitterMode;}
	void SetFileSorting (InsertIndexManager::eFileSorting           fileSorting)  {m_FileSorting  = fileSorting;}


	bool GetCtxMenuIntegration()                     const {return m_CtxMenuIntegration;}
	bool GetUseDefValsForThreadSearch()              const {return m_UseDefValsForThreadSearch;}
	bool GetShowSearchControls()                     const {return m_ShowSearchControls;}
	bool GetShowDirControls()                        const {return m_ShowDirControls;}
	bool GetShowCodePreview()                        const {return m_ShowCodePreview;}
	bool GetDisplayLogHeaders()                      const {return m_DisplayLogHeaders;}
	bool GetDrawLogLines()                           const {return m_DrawLogLines;}
	void GetFindData(ThreadSearchFindData& findData) const {findData = m_FindData;}
	ThreadSearchFindData& GetFindData()                    {return m_FindData;}
	ThreadSearchViewManagerBase::eManagerTypes GetManagerType() const {return m_pViewManager->GetManagerType();}
	ThreadSearchLoggerBase::eLoggerTypes       GetLoggerType()  const {return m_LoggerType;}
	long                                       GetSplitterMode() const {return m_SplitterMode;}
	InsertIndexManager::eFileSorting           GetFileSorting()  const {return m_FileSorting;}
    wxString GetCodeSnippetsIndex(){return m_CodeSnippetsIndexFilename;}
    void     SplitThreadSearchWindow();
    void     UnsplitThreadSearchWindow();
    void     ResetNotebookSashPosition();
    void     UserResizingWindow(wxSizeEvent &event);


	void RunThreadSearch(const wxString& text, bool isCtxSearch = false);


	void OnThreadSearchViewDestruction();


	void ShowToolBar(bool show);


	bool IsToolbarVisible();



	wxFont              m_Conf_font;
    wxBoxSizer*         m_pMainSizer;
    MainPanel*          m_pMainPanel;
    wxSplitterWindow*   m_pMainSplitter;

    cbAuiNotebook*      m_pEdNotebook;
    wxWindow*           m_pThreadSearchViewParentBak;
    wxWindow*           m_pEdNotebookParentBak;
    wxWindow*           m_pParent;
    bool                m_bSashWindowResizing;
protected:

	virtual void OnAttach();


	virtual void OnRelease(bool appShutDown);


	virtual void LoadConfig(bool &showPanel, int &sashPosition,
							ThreadSearchViewManagerBase::eManagerTypes& mgrType,
							wxArrayString& searchPatterns);


	virtual void SaveConfig(bool showPanel, int sashPosition,
							ThreadSearchViewManagerBase::eManagerTypes mgrType,
							const wxArrayString& searchPatterns);

private:

	void OnMnuViewThreadSearch(wxCommandEvent& event);


	void OnMnuSearchThreadSearch(wxCommandEvent& event);


	void OnCtxThreadSearch(wxCommandEvent& event);


	void OnMnuViewThreadSearchUpdateUI(wxUpdateUIEvent& event);


	void OnMnuSearchThreadSearchUpdateUI(wxUpdateUIEvent& event);


	void OnBtnOptionsClick(wxCommandEvent& event);
	void OnBtnSearchClick (wxCommandEvent& event);
	void OnCboSearchExprEnter(wxCommandEvent &event);


	void RemoveMenuItems();



	bool GetCursorWord(wxString& sWord);


	int GetInsertionMenuIndex(const wxMenu* const pCtxMenu);



	void OnMnuEditCopy(wxCommandEvent& event);
	void OnMnuEditCopyUpdateUI(wxUpdateUIEvent& event);
    void OnMnuEditPaste(wxCommandEvent& event);

    void OnSashPositionChanged(wxSplitterEvent& event);
    void OnIdle(wxIdleEvent& event);
    void OnCodeSnippetsNewIndex(CodeSnippetsEvent& event);


	wxString                             m_SearchedWord;
	ThreadSearchFindData                 m_FindData;
	ThreadSearchView*                    m_pThreadSearchView;
	ThreadSearchViewManagerBase*         m_pViewManager;

	wxToolBar*                           m_pToolbar;
	bool                                 m_CtxMenuIntegration;
	bool                                 m_UseDefValsForThreadSearch;

    bool                                 m_ShowSearchControls;
    bool                                 m_ShowDirControls;
    bool                                 m_ShowCodePreview;
    ThreadSearchLoggerBase::eLoggerTypes m_LoggerType;
    bool                                 m_DisplayLogHeaders;
    bool                                 m_DrawLogLines;
    bool                                 m_OnReleased;
    wxComboBox*                          m_pCboSearchExpr;
    wxSplitMode                          m_SplitterMode;

    InsertIndexManager::eFileSorting     m_FileSorting;
    bool                                 m_bSashPositionChanged;
    int                                  m_EdNotebookSashPosition;
    wxString                             m_CodeSnippetsIndexFilename;
	DECLARE_EVENT_TABLE();
};

#endif
